package bsi.vn.Data;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import bsi.vn.FirstApp.R;

import android.content.Context;
import android.graphics.Color;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ContractATMListAdapter extends ArrayAdapter<ATMData>{

	private Context context;
	private int resID;
	private ArrayList<ATMData> list;
	
	public ContractATMListAdapter(Context context, int textViewResourceId,
			List<ATMData> objects) {
		super(context, textViewResourceId, objects);
		this.context = context;
		resID = textViewResourceId;
		list = (ArrayList<ATMData>) objects;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		if(convertView==null) 
        { 
            LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
            convertView=inflater.inflate(R.layout.fragment_contract_atmlist_item, null);                     
        }
		
		TextView tvsno = (TextView) convertView.findViewById(R.id.tvCALcno);
		TextView tvcit = (TextView) convertView.findViewById(R.id.tvCALcit);
		TextView tvdep = (TextView) convertView.findViewById(R.id.tvCALdep);
		TextView tvnum = (TextView) convertView.findViewById(R.id.tvCALnumber);
		ATMData data = list.get(position);
		tvsno.setText(data.getSerialNo());
		tvcit.setText(data.getProvince());
		tvnum.setText(position+1 +"");
		tvnum.setTextColor(Color.RED);
		if(data.getDeploy()!= null){
			SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
			String date = format.format(data.getDeploy());
			tvdep.setText(date);
			tvdep.setTextColor(Color.BLACK);
		}else{
			tvdep.setText(R.string.CTAnoData);
			tvdep.setTextColor(Color.RED);
		}
		
		
		return convertView;
	}
	
}
